/**data structure used for storing Directories,files in a hierarchical manner in our vfs**/


#ifndef NARYTREE_H_INCLUDED
#define NARYTREE_H_INCLUDED
#include "header.h"
#include "constants.h"
#include <stdio.h>

typedef struct nary_tree
{
    fdesc *data;
    struct nary_tree *child;
    struct nary_tree *siblings;
} n_tree;


/**used to create first node in an nary tree that will be the root node**/
int init_root(n_tree *root, fdesc *data);

/**allocate memory to node**/
n_tree* allocate_node(fdesc *fd);

/**search in the sibling nodes of a node for the path specified in fd**/
int node_searchInSibling(n_tree *root, char data[CHARSIZE],
                         n_tree** resultnode,n_op_type operation);

/**used to search for position where node is to be inserted **/
int insert_in_subtree(n_tree **node,fdesc *data,int index);


/**local method for validating duplicate file**/
int isDuplicateFile(n_tree* root,fdesc* data);

/**used to insert a new node*/
int insert_node(n_tree **node,fdesc *data);

/**used to traverse the tree as InOrder,PreOrder,PostOrder,level order
works like ls command in linux file system**/
void n_node_traversal(n_tree *root,n_traversal_type order,li_search s_type,FILE *ft);

void list_dir(n_tree* root,n_traversal_type traversal,
              li_search search_type,char *opfile);

/**for making tokens**/
int makeTokens(char fp[],char p[][CHARSIZE]);

/**used to validate thefiledescriptor must be made generic for all datastructures**/
int validate_file_descriptor(fdesc *fd);

/**to delete anode from subtree search recursively using this function**/
int delete_from_subtree(n_tree** root, fdesc* data, int index);

/**used to delete a node**/
int delete_node(n_tree** root, fdesc *data);

int unmount_travesal(n_tree* root);


int insertDirRecursively(int index,int tokens,char path[][CHARSIZE],
                         n_tree *prevnode,int is_child,fdesc* data);

/**to move a subtree source dir to dest directory**/
int  move_from_subtree(n_tree* root,fdesc *src_dir,fdesc *dest_dir);

int move_Function(n_tree* root,char *srcpath,char *destpath,char *temp_type);

n_tree* tree_traversal(n_tree *root,char path[][CHARSIZE],char* f_type,int flag);

int update_path(n_tree *node,int flag);

#endif // NARYTREE_H_INCLUDED

